package cn.stronglink.oil.widget;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import cn.stronglink.oil.R;


/**
 * Created by Tgb on 2017/4/16.
 */

public class ProgressDialog extends Dialog {
    private Context mContext;
    private ImageView iv_progress;
    private TextView tv_progress_msg;
    private String customMessage;
    private static ProgressDialog instance;

    public static ProgressDialog getInstance(Context context) {
        if (instance == null) {
            instance = new ProgressDialog(context);
        }
        return instance;
    }

    public ProgressDialog(Context context) {
        super(context, R.style.MyDialog);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_progressbar);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        initView();
        initData();
    }

    private void initData() {
        if (customMessage != null) {
            tv_progress_msg.setText(customMessage);
        }
    }

    /**
     * 设置信息
     * @param msg
     */
    public void setMessage(String msg) {
        this.customMessage = msg;
    }

    private void initView() {
        iv_progress = (ImageView) findViewById(R.id.iv_progress);
        tv_progress_msg = (TextView) findViewById(R.id.tv_message);
    }

    @Override
    public void show() {
        super.show();
        // 加载动画  
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(mContext, R.anim.progress_animal);// 使用ImageView显示动画  
        iv_progress.startAnimation(hyperspaceJumpAnimation);
        tv_progress_msg.setText(customMessage);// 设置加载信息  
    }
}
